﻿using System;
using System.Xml.Serialization;
using PrearrangedChaos.AgileZen.Service.Rest;

namespace PrearrangedChaos.AgileZen.Service.Model
{
    [XmlType(AnonymousType = true)]
    [XmlRoot(ElementName = "role", Namespace = "", IsNullable = false)]
    [ZenRestRequest("projects/{ProjectId}/roles/{RoleId}")]
    public class RoleUpdater : ModelBase, IRoleUpdater
    {
        private string _name;
        private ApiAccess? _access;

        /// <remarks/>
        [XmlElement(ElementName = "name")]
        public string NameXmlElement
        {
            get { return _name; }
            set
            {
                if (!string.IsNullOrEmpty(value))
                    _name = value;
                else
                    _name = null;

                this.Unmodified("name");
            }
        }

        [XmlIgnore]
        public string Name
        {
            get { return _name; }
            set
            {
                if (_name == value)
                    return;

                _name = value;
                this.Modified("name");
            }
        }

        public bool NameXmlElementSpecified { get { return this.IsModified("name"); } }

        /// <remarks/>
        [XmlElement(ElementName = "access")]
        public string AccessXmlElement
        {
            get { return this.Access == null ? null : this.Access.ToString().ToLower(); }
            set
            {
                this.Access = (ApiAccess)Enum.Parse(typeof(ApiAccess), value, true);
                this.Unmodified("access");
            }
        }

        public bool AccessXmlElementSpecified { get { return this.IsModified("access"); } }

        [XmlIgnore]
        public ApiAccess? Access
        {
            get { return _access; }
            set
            {
                if (_access == value)
                    return;

                _access = value;
                this.Modified("access");
            }
        }
    }
}